package panel.login;

import frame.Login;
import global.Const;
import other.DButton;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Index extends JPanel implements ActionListener {
    public Index() {
        init();
    }

    private void init() {
        setBounds(0, 0, Const.PANEL_WIDTH, Const.PANEL_HEIGHT);
        setLayout(null);
        setOpaque(false);
        setVisible(false);

        // 注册按钮
        DButton signUp = new DButton("注 册");
        signUp.setForeground(Color.black);
        signUp.setBackground(Color.white);
        signUp.setBounds(30, 825, 200, 75);
        signUp.addActionListener(this);
        signUp.repaint();
        add(signUp);

        // 登录按钮
        DButton logIn = new DButton("登 录");
        logIn.setBounds(310, 825, 200, 72);
        logIn.addActionListener(this);
        logIn.repaint();
        add(logIn);
    }

    public void open() {
        setVisible(true);
    }

    public void close() {
        setVisible(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.print(e.getActionCommand() + "\n");
        switch (e.getActionCommand()) {
            case "注 册":
                close();
                Login.signUpPanel.open();
                break;
            case "登 录":
                close();
                Login.logInPanel.open();
                break;
        }
    }
}
